/* 
Scenic Graphics Library
Copyright (C) 2007 Jouni Tulkki

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USApackage scenic;
*/

package scenic;

/**
 * Contains constants for different pixel formats. All
 * formats are specified from most significant bit (MSB) to 
 * least significant bit (LSB). In memory the bytes
 * area stored from LSB to MSB. So the format A8R8G8B8 is
 * stored in memory in the following order: blue, green, red and 
 * alpha.
 */
public class Format {
	/**
	 * Alpha, red, green and blue channels using 8-bits 
	 * per channel.
	 */
	public static final int A8R8G8B8 = 0;
	/**
	 * Alpha, red, green and blue channels using 8-bits 
	 * per channel. Same format as BufferedImage.TYPE_4BYTE_ABGR.
	 */
	public static final int R8G8B8A8 = 5;
	/**
	 * Red, green and blue channels using 8-bits 
	 * per channel. The alpha channel is set to 1.  
	 * Same format as BufferedImage.TYPE_3BYTE_BGR.
	 */
	public static final int R8G8B8 = 1;
	/**
	 * Luminance using 8-bits. The red, green and blue channels
	 * are set to the luminance value. The alpha channel is set to 1.
	 */
	public static final int L8 = 2;
	/**
	 * Alpha using 8-bits. The red, green and blue channels
	 * are set to 0.
	 */
	public static final int A8 = 3;
	/**
	 * A single alpha-luminance value using 8-bits. 
	 * The red, green, blue and alpha channels are set 
	 * to the alpha-luminance value.
	 */
	public static final int AL8 = 4;
	
	/**
	 * Alpha, blue, green and red channels using 16-bit floats
	 * per channel.
	 */
	public static final int ABGR_16F = 6;
	/**
	 * Alpha, blue, green and red channels using 32-bit floats
	 * per channel.
	 */
	public static final int ABGR_32F = 7;
	/**
	 * Alpha and luminance channels using 32-bit floats
	 * per channel.
	 */
	public static final int AL_32F = 8;
	/**
	 * Alpha and luminance channels using 64-bit floats
	 * per channel.
	 */
	public static final int AL_64F = 9;
	
	public static final int A8B8G8R8 = 10;
	public static final int X8R8G8B8 = 11;
	public static final int X8B8G8R8 = 12;
	public static final int R8G8B8X8 = 13;
	public static final int B8G8R8X8 = 14;
	public static final int B8G8R8A8 = 15;
	public static final int A1R8G8B8 = 16;
	
	/**
	 * Contains information about a pixel format.
	 */
	public static class Info {
		private int size;
		
		private Info(int size) {
			this.size = size;
		}		
		
		/**
		 * Returns the size of a pixel in bytes.
		 */
		public int getSize() {
			return size;
		}
	}
	
	private static final Info[] formats = {
		new Info(4),
		new Info(3),
		new Info(1),
		new Info(1),
		new Info(1),
		
		new Info(4),
		new Info(8),
		new Info(16),
		new Info(8),
		new Info(8),

		new Info(4),
		new Info(4),
		new Info(4),
		new Info(4),
		new Info(4),

		new Info(4),		
		new Info(4)		
	};
	
	private Format() {
	}
	
	/**
	 * Gets the information for the given format.
	 */
	public static Info getInfo(int format) {
		return formats[format];
	}
	
	/**
	 * Gets the number of bytes per pixel for the given format.
	 */
	public static int getPixelSize(int format) {
		return formats[format].size;
	}
}
